package com.ego.item.controller;


import com.ego.item.entity.Specification;
import com.ego.item.service.SpecificationService;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/spec")
public class SpecificationController {
    @Resource
    private SpecificationService specificationService;

    @GetMapping("/{id}")
    public ResponseEntity<String> querySpecificationByCategoryId(@PathVariable("id") Long cid) {
        Specification specification = specificationService.queryByCid(cid);
        if (specification == null){
            return new ResponseEntity<>(HttpStatus.NOT_FOUND);
        }
        return  ResponseEntity.ok(specification.getSpecifications());
    }

    @PutMapping
    public ResponseEntity<Void> updateSpecification(Specification specification){
        specificationService.updateSpecification(specification);
        return ResponseEntity.ok().build();
    }

    @PostMapping
    public ResponseEntity<Void> saveSpecification(Specification specification){
        specificationService.save(specification);
        return ResponseEntity.ok().build();
    }


}
